<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Neutron Panel</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/static/css/login.css">
    <style>
        .win_app {
            display: none;
        }
    </style>
    <script>
        CHECK_LOGIN = 0
        function load_ready() {
            document.getElementById("win_app").style.display = "block";
            document.getElementById("win_app").style.visibility = "visible";
        }
        function error() {
            alert("加载失败！");
            location.reload()
        }
    </script>
    <script src="/static/js/login.js"></script>
    <link rel="icon" href="/static/img/neutron.png">
</head>

<body>
    <div id="win_app">
        <input id="username_input" type="text" name="username" autofocus placeholder="用户名">
        <input id="password_input" type="password" name="password" autofocus placeholder="密码">
        <button id="login_button" onclick="login()">&gt;
        </button>
    </div>
    <script>
        // 检查js加载
        if (CHECK_LOGIN != 1) {
            error();
        }
        load_ready()
        function login() { // 登录
            username = document.getElementById("username_input").value;
            password = document.getElementById("password_input").value;
            if (username == "" || password == "") {
                alert("用户名或密码不能为空！");
                return;
            }
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "/api/login", true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    var json = JSON.parse(xhr.responseText);
                    // 登录
                    if (json.code == 0) {
                        location.href = "/";
                    } else {
                        alert(json.msg);
                    }
                }
            }
            xhr.send("username=" + username + "&password=" + password);
        }
    </script>
</body>

</html>